import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';

/// 底部弹出，内容自定义（不一定是选择）
class CustomListviewBottom extends StatelessWidget {
  const CustomListviewBottom({required this.title, required this.child, required this.height, required this.isScroll, super.key});

  /// 内容
  final Widget child;

  /// 标题
  final String title;

  /// 高度
  final double height;

  /// 是否需要滑动
  final bool isScroll;

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
          gradient: const LinearGradient(
            colors: [
              Color(0xFFE7EAFF),
              Colors.white,
              Colors.white,
            ],
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
          ),
          borderRadius: BorderRadius.only(topLeft: Radius.circular(17.w),topRight: Radius.circular(17.w))),
      height: height.w,
      child: !isScroll
          ? SingleChildScrollView(
              child: Column(
                children: [
                  Padding(
                    padding: EdgeInsets.all(13.w),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text(
                          title,
                          style: TextStyle(
                            fontSize: 18.w,
                            color: const Color(0xFF262F38),
                          ),
                        ),
                        Container(
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(17.w),
                            color: Colors.white,
                          ),
                          height: 24.w,
                          width: 24.w,
                          child: Icon(
                            Icons.close,
                            size: 18.w,
                            color: const Color(0xFF262F38),
                          ),
                        ).clickOnce(Get.back),
                      ],
                    ),
                  ),
                  SafeArea(child: child),
                ],
              ),
            )
          : Column(
              children: [
                Padding(
                  padding: EdgeInsets.all(13.w),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        title,
                        style: TextStyle(
                          fontSize: 18.w,
                          color: const Color(0xFF262F38),
                        ),
                      ),
                      Container(
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(17.w),
                          color: Colors.white,
                        ),
                        height: 24.w,
                        width: 24.w,
                        child: Icon(
                          Icons.close,
                          size: 18.w,
                          color: const Color(0xFF262F38),
                        ),
                      ).clickOnce(Get.back),
                    ],
                  ),
                ),
                Expanded(
                  child: SafeArea(child: child),
                ),
              ],
            ),
    );
  }

  static Future<T?> show<T>(
      {required Widget child,
      required String title,
      double height = 300,
      bool isDismissible = true,
      bool isScrollControlled = false,
      bool isScroll = false,
      Color barrierColor = Colors.black54}) async {
    return await Get.bottomSheet<T>(
      CustomListviewBottom(
        title: title,
        height: height,
        isScroll: isScroll,
        child: child,
      ),
      isDismissible: isDismissible,
      barrierColor: barrierColor,
      isScrollControlled: isScrollControlled, //在不指定高度的情况下，getx bottomsheet 会自适应高度，一般高度最高是当前手机屏幕的5/9 ，如果需要指定高度，需要特殊设置
    );
  }
}
